package com.bjesc_b2c.app.appraiset.widget.popupwindow;

import android.content.Context;
import android.support.annotation.IdRes;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.bjesc_b2c.app.appraiset.R;
import com.bjesc_b2c.app.appraiset.widget.BasePopupWindow;
import com.bjesc_b2c.app.appraiset.widget.view.RangeSeekBar;
import com.orhanobut.logger.Logger;
import com.rxretrofit_build.model.RxBusBean;

import master_bean.FindCarBean;

/**
 * Created by yidong on 2017/5/24.
 */

public class FilterCarPop extends BasePopupWindow implements View.OnClickListener,RadioGroup.OnCheckedChangeListener,RangeSeekBar.OnRangeChangedListener{
    private FindCarBean carBean = new FindCarBean();
    private int installment;
    private FilterCallback callback;
    private Context context;
    private TextView carBrand;
    private RangeSeekBar rangeSeekBar;
    private String price;
    public FilterCarPop(Context context, FilterCallback callback) {
        super(context, null);
        this.context = context;
        this.callback = callback;
    }

    @Override
    protected void initViews() {
        view = inflater.inflate(R.layout.layout_pop_filter,null);
        carBrand = (TextView)view.findViewById(R.id.tv_car_brand);
        rangeSeekBar = (RangeSeekBar)view.findViewById(R.id.rang_seekbar);
        rangeSeekBar.setOnRangeChangedListener(this);
        view.findViewById(R.id.rlty_car_brand).setOnClickListener(this);
        view.findViewById(R.id.btn_determine).setOnClickListener(this);
    }
    @Override
    protected void setView() {
        super.setView();
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    }
    @Override
    protected int setRootViewId() {
        return R.id.lin_poproot;
    }

    @Override
    public void onRangeChanged(float lowerRange, float upperRange) {
        Math.floor(lowerRange);
        price = lowerRange+"-"+upperRange;
        Logger.d(Math.floor(lowerRange));
        Logger.d(upperRange);
        Logger.d(price);
        carBean.setPrice(price);
    }

    @Override
    public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_all://全部
                carBean.setInstallment(0);
                break;
            case R.id.rbtn_staging://分期
                carBean.setInstallment(1);
                break;
            case R.id.rbtn_full_amount://全款
                carBean.setInstallment(2);
                break;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rlty_car_brand://品牌跳转
                if (callback !=null && carBean != null){
                    callback.selectedBrand();
                }
                break;
            case R.id.btn_determine://确定
                if (callback !=null && carBean != null){
                    callback.inquireCar(carBean);
                }
                dismiss();
                break;
        }
    }
    public interface FilterCallback{
        void inquireCar(FindCarBean carBean);
        void selectedBrand();
    }

    @Override
    protected void doOnNext(RxBusBean rxBusBean) {
        carBrand.setText(rxBusBean.getRequestMark());
    }

}
